package com.elepro.shoppingmall.controller;

import com.elepro.shoppingmall.entity.Message;
import com.elepro.shoppingmall.service.user.MessageServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class MessageController {
    @Resource
    private MessageServiceImpl messageService;

    //发布消息
    @PostMapping("/insertMessage")
    public boolean insertMessage(@RequestBody Message message) {
        int result = messageService.insertMessage(message);
        return result == 1;
    }

    //删除消息
    @GetMapping("/deleteMessageById")
    public boolean deleteMessageById(long id) {
        int result = messageService.deleteMessageById(id);
        return result == 1;
    }

    //查询所有消息
    @GetMapping("/getAllMessage")
    public List<Message> getAllMessage() {
        return messageService.getAllMessage();
    }

    //用户查询所有消息
    @GetMapping("/getUserAllMessage")
    public List<Message> getUserAllMessage(@RequestParam("id") long userId) {
        return messageService.getUserAllMessage(userId);
    }
}
